package com.idp.web.bp.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.base.BaseController;
import com.common.constant.SysMessage;
import com.common.enums.CommonCode;
import com.common.model.JsonModel;
import com.common.model.PageModel;
import com.common.utils.ValidateUtil;
import com.idp.biz.bpcomments.entity.BpComments;
import com.idp.biz.bpcomments.service.BpCommentsService;

 /**
 * 点赞评论controller
 * 
 * @author Stone
 *
 */
@Controller
@RequestMapping("/bpComments/")
public class BpCommentsController extends BaseController {
	private static Logger logger = LoggerFactory.getLogger(BpCommentsController.class);

	@Autowired
	private BpCommentsService bpCommentsService;
	
	/**
	 * 初始化查询页面
	 * Stone 2019-07-29
	 * @return
	 */
	@RequestMapping(value="init",method=RequestMethod.GET)
	public String init(){
		logger.info("点赞评论");
		return "bp/bpComments/bpCommentsList";
	}
	
	/**
	 * 分页查询
	 * Stone 2019-07-29
	 * @param bpComments
	 * @param page
	 * @return
	 */
	@RequestMapping(value="list",method=RequestMethod.POST)
	@ResponseBody
	public PageModel<BpComments> list(BpComments bpComments,PageModel<BpComments> page){
		return bpCommentsService.findByPage(bpComments, page);
	}

	/**
	 * 新增修改页面初始化
	 * Stone 2019-07-29
	 * @param id
	 * @param request
	 * @return
	 */
	@RequestMapping(value="bpComments",method=RequestMethod.GET)
	public String bpComments(String id,HttpServletRequest request){
		if(ValidateUtil.isNotEmpty(id)){
			BpComments bpComments = bpCommentsService.getById(id);
			request.setAttribute("bpComments", bpComments);
		}
		return "bp/bpComments/bpCommentsEdit";
	}
	
	/**
	 * 详情
	 * Stone 2019-07-29
	 * @param id
	 * @param request
	 * @return
	 */
	@RequestMapping(value="view",method=RequestMethod.GET)
	public String view(String id,HttpServletRequest request){
		if(ValidateUtil.isNotEmpty(id)){
			BpComments bpComments = bpCommentsService.getById(id);
			request.setAttribute("bpComments", bpComments);
		}
		return "bp/bpComments/bpCommentsView";
	}
	
	/**
	 * 保存
	 * Stone 2019-07-29
	 * @param bpComments
	 * @return
	 */
	@RequestMapping(value="save",method=RequestMethod.POST)
	@ResponseBody
	public JsonModel save(BpComments bpComments){
		JsonModel json = new JsonModel();
		if(ValidateUtil.isNotEmpty(bpComments.getId())){
			bpCommentsService.update(bpComments);
			json.setMessage(SysMessage.COMMON_UPDATE_SUCCESS);
		} else{
			bpCommentsService.add(bpComments);
			json.setMessage(SysMessage.COMMON_ADD_SUCCESS);
		}
		return json;
	}
	
	/**
	 * 删除
	 * Stone 2019-07-29
	 * @param id
	 * @return
	 */
	@RequestMapping(value="delete",method=RequestMethod.POST)
	@ResponseBody
	public JsonModel delete(BpComments bpComments){
		JsonModel json = new JsonModel();
		bpComments.setStatus(CommonCode.CONTENT_IS_DELETE.getValue());
		bpComments.setSymbol(CommonCode.N.getValue());
		bpCommentsService.update(bpComments);
		json.setMessage(SysMessage.COMMON_DELETE_SUCCESS);
		return json;
	}
	
	/**
	 * 屏蔽评论内容
	 */
	@RequestMapping(value="changeStatus",method=RequestMethod.POST)
	@ResponseBody
	public JsonModel changeStatus(BpComments bpComments){
		JsonModel json = new JsonModel();
		bpCommentsService.update(bpComments);
		json.setMessage(SysMessage.COMMON_OPERATE_SUCCESS);
		return json;
	}
	
	/**
	 * 加精/取消加精
	 */
	@RequestMapping(value="changeIsClassic",method=RequestMethod.POST)
	@ResponseBody
	public JsonModel changeIsClassic(BpComments bpComments){
		JsonModel json = new JsonModel();
		bpCommentsService.update(bpComments);
		json.setMessage(SysMessage.COMMON_OPERATE_SUCCESS);
		return json;
	}
	
	/**
	 * 置顶/取消置顶
	 */
	@RequestMapping(value="changeIsTop",method=RequestMethod.POST)
	@ResponseBody
	public JsonModel changeIsTop(BpComments bpComments){
		JsonModel json = new JsonModel();
		bpCommentsService.update(bpComments);
		json.setMessage(SysMessage.COMMON_OPERATE_SUCCESS);
		return json;
	}
}
